package com.lj.mcore.tools;

import com.lj.mcore.entity.Area;
import com.lj.mcore.entity.StoreClass;

import java.util.*;

public class StoreClassTools {

    public static String parentPath(StoreClass storeClass){
        String path="";
        StoreClass parent = storeClass.getParent();
        if (parent!=null){
            path=">"+parent.getClassName();

            if (parent.getParent()!=null){
                path=">"+parentPath(parent.getParent());
            }

        }

        if (path.length()>0){
            path=path.substring(1,path.length());
        }
        return path;
    }

    public static List ergodicChildren(List<StoreClass> storeClassList){
        List list = new ArrayList();
        for (StoreClass storeClass:storeClassList){
            Map map = new HashMap();
            map.put("scid",storeClass.getId());
            map.put("className",storeClass.getClassName());
            if (storeClass.getChilds().size()>0){
                map.put("children",ergodicChildren(storeClass.getChilds()));
            }
            list.add(map);
        }
        return list;
    }

    public static List ergodicParentIds(StoreClass storeClass){
        List list = new ArrayList();
        if (storeClass!=null){
            list.add(storeClass.getId());
            StoreClass parent = storeClass.getParent();
            list.addAll(ergodicParentIds(parent));
        }
        return list;
    }
}
